<?php

/**
 * Created by PhpStorm.
 * User: Yieong
 * Date: 2016/11/8
 * Time: 下午10:17
 */
class TaskController extends AdminBaseController {

    public function index(){
        $this->setTitle('任务完成度');

        $filter = new PubFilter();
        $chart  = new PubChart();
        $grid   = new PubGrid();

        //$dictTaskType = TaskService::dictTaskType();

        $lod_special_id = $this->R('special_id');
		$lodos = $this->R('os');
		$filter->addSpecialFilter(false,2);
		$filter->addOsFilter($lod_special_id,true,2)
        ->addServerFilter($lod_special_id,$lodos,true,false,2)
            ->addFilter('time_start', 'input', PubFunc::t('时间'), array('date' => 'day', 'value' => date('Y-m-d', strtotime('-7 day'))),2)
            ->addFilter('time_end', 'input', PubFunc::t('至'), array('date' => 'day', 'value' => date('Y-m-d', strtotime('-1 day'))),2)
            ->addExport();

        $params = $filter->get();
        
        $params = $this->indexCommon($params);

        $header = TaskService::indexHeader($params);
        $data   = TaskService::indexData($params);

        if($filter->isExport()){
            $filename = LibExcel::getFilename('任务完成度', $params);
            LibExcel::exportCsv($header, $data, $filename);
        }else{
            $grid->addGrid($header, $data, array(
                'length' => 50,
            	'fix'   => array(
            		'col' => 1
            	)
            ));

            $this->out['filter'] = $filter->show();
            $this->out['chart']  = $chart->show();
            $this->out['grid']   = $grid->show();
            $this->out['is_ana'] = 2;
        }
    }
    
    public function realIndex(){
    	$this->setTitle('实时任务完成度');
    
    	$filter = new PubFilter();
    	$chart  = new PubChart();
    	$grid   = new PubGrid();
    
    	//$dictTaskType = TaskService::dictTaskType();
    
    	$lod_special_id = $this->R('special_id');
    	$lodos = $this->R('os');
    	$filter->addSpecialFilter(false,2);
    	$filter->addOsFilter($lod_special_id,true,2)
    	->addServerFilter($lod_special_id,$lodos,true,false,2)
//     	->addFilter('time_start', 'input', PubFunc::t('时间'), array('date' => 'day', 'value' => date('Y-m-d', strtotime('-7 day'))),2)
//     	->addFilter('time_end', 'input', PubFunc::t('至'), array('date' => 'day', 'value' => date('Y-m-d', strtotime('-1 day'))),2)
    	->addExport();
//    	$filter->addFilter('recDate', 'input', '时间');
    
    	$params = $filter->get();
    
    	$params = $this->indexCommon($params);
    
    	$header = TaskService::indexHeader($params);
    	$data   = TaskService::realIndexData($params);
    
    	if($filter->isExport()){
    		$filename = LibExcel::getFilename('任务完成度', $params);
    		LibExcel::exportCsv($header, $data, $filename);
    	}else{
    		$grid->addGrid($header, $data, array(
    				'length' => 50,
    				'fix'   => array(
    						'col' => 1
    				)
    		));
    
    		$this->out['filter'] = $filter->show();
    		$this->out['chart']  = $chart->show();
    		$this->out['grid']   = $grid->show();
    		$this->out['is_ana'] = 2;
    	}
    }

}